/*
 * 文件名：ByteFOrmatHandler.java
 * 版权：亚信科技(南京)版权所有
 * 描述：TODO
 * 修改人：napo
 * 修改时间：2015-12-14
 * 修改内容：TODO
 */
package com.ailk.bigdata.etl.realstream.server.service.impl;

import io.netty.buffer.ByteBuf;

import com.ailk.bigdata.etl.realstream.server.service.FormatHandler;

/**
 * @description TODO
 * @author [xuwei3]
 * @version [版本号,2015-12-14]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class ByteFormatHandler extends FormatHandler
{

	/**
	 * @see com.ailk.bigdata.etl.realstream.server.service.FormatHandler#handleRequest(io.netty.buffer.ByteBuf,
	 *      java.lang.StringBuilder)
	 */
	@Override
	public void handleRequest(ByteBuf byteBuf, StringBuilder content)
	{
		String value = "";
		if (1 == length)
		{
			short valueT = byteBuf.readUnsignedByte();
			value = Short.toString(valueT);
			if (255 == valueT)
			{
				value = "";
			}
		}
		else if (2 == length)
		{
			int valueT = byteBuf.readUnsignedShort();
			value = Integer.toString(valueT);
			if (65535 == valueT)
			{
				value = "";
			}
		}
		else if (4 == length)
		{
			long valueT = byteBuf.readUnsignedInt();
			value = Long.toString(valueT);
			if (4294967295L == valueT)
			{
				value = "";
			}
		}
		// else if (8 == length)
		// {
		// value = Long.toString(byteBuf.readLong());
		// }
		// else if (16 == length)
		// {
		// value =
		// Long.toString(byteBuf.readLong()).concat(Long.toString(byteBuf.readLong()));
		// }
		else
		{
			byteBuf.readBytes(length);
		}
		content.append(value);
		if (getSuccessor() != null)
		{
			content.append(separator);
			getSuccessor().handleRequest(byteBuf, content);
		}
		value = null;
	}

}
